package com.atguigu.gulimall.juc.demo;

import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicStampedReference;

class AtomicRefrenceUser{
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public AtomicRefrenceUser() {
    }

    public AtomicRefrenceUser(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "AtomicRefrenceUser{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

public class AtomicRefrenceDemo {
    public static void main(String[] args) {
//        AtomicStampedReference atomicStampedReference = new AtomicStampedReference();
        AtomicRefrenceUser zh3 = new AtomicRefrenceUser("zhangsan",20);
        AtomicRefrenceUser li4 = new AtomicRefrenceUser("lisi",26);
        AtomicReference<AtomicRefrenceUser> atomicReference = new AtomicReference<AtomicRefrenceUser>();
        atomicReference.set(zh3);
        System.out.println(atomicReference.compareAndSet(zh3,li4)+"\t"+atomicReference.get().toString());
        System.out.println(atomicReference.compareAndSet(zh3,li4)+"\t"+atomicReference.get().toString());
    }
}
